
#ifndef   __STORAGE_H__
#define   __STORAGE_H__

#define   STORAGE_FREE_ENTRY_TOKEN	0xFE

enum
{
	STORAGE_ERR__NO_FRE_MEM = -1,
	STORAGE_ERR__WRONG_DIRECTORY = -2,
	STORAGE_ERR__ENTRY_NOT_FOUND = -3,
	STORAGE_ERR__ENTRY_ALREADY_EXIST = -4
};

extern unsigned int storage_index;

typedef struct
{
		int (*add) ( void *entry); /* add antry to directory return addr; NOTE: must be first in the struct */	
		int (*find) ( void *ref ); /* comp the data of first field of the entry; return addr of entry */
		void(*print)(unsigned int out_dev); 
		unsigned int directory_addr;	  /* address of directory of the entry storage */
		unsigned short entry_size;  /* size of one entry */
		unsigned short entrys_count;  /* entrys_size * entry_count = directory_size */
}storage_directory_properties_t;

extern const storage_directory_properties_t directories[];

//#define   DIR_PROP_INDEX	((unsigned int)directories[0])

#define DIR_INDEX(DIR_ADDR) (((unsigned int)DIR_ADDR-(unsigned int)&directories[0])/sizeof(storage_directory_properties_t))


#define   DIR_PROP 		directories[directory]


typedef struct 
{	
	unsigned int address;
	int (*Write)( unsigned int addr, void *data, unsigned int data_size); /* return count of writed bytes or -1 if fail*/
	int (*Read) ( unsigned int addr, void *data, unsigned int data_size); /* return count of writed bytes or -1 if fail*/
	int (*comp)(unsigned int addr,void *data,unsigned int data_size);/*return number of matched bytes bytes or -1 if fail*/
	int (*mset)(unsigned int addr, unsigned char set_byte, unsigned int byte_count); /* like memset */
	int (*add) ( unsigned int directory, void *entry); /* add antry to directory return addr */
	int (*find)( unsigned int directory, void *ref); /* return addr of entry */
	int (*delete_entry)( unsigned int directory, void *entry ); /* return addr of entry */
	int (*delete_directory)( unsigned int directory ); /* return addr of entry */
	int (*del_all)( void ); /* return 0 or -1 if fail */
	void(*print)( unsigned int directory, unsigned int out_dev ); /* send to out device in printable format */
	int (*entrys_counter)( unsigned int directory ); /* return: how many entrys into directory */
}storage_class_t;


extern storage_class_t storage;

int storage_find_free( unsigned int directory ); /* return addr of free place for the entry */

/* return: how many entrys into directory */
int storage_entrys_counter( unsigned int directory );

#endif
